//会员店项目特效工具包
//会员店中高重用的特效js既可以放入其中
if (typeof (Action) === "undefined" || !Action) {
	var Action = {};
}
// 无间隙滚动特效实现,支持纵向滚动
// 必须传入div样式或者要显示的高度，这样才能实现在一定高度中无间隙滚动
Action.Scroll = function(p) {
	p = p || {};
	this.renderId = p.renderId;//要渲染的DIV
	this.speed = p.speed || 30;//越小越快
	this.cls = p.cls;//自定义样式
	this.height = p.height;//div显示高度
	this.timmer = null;
	//初始化dom
	if(p.cls) {
		$("#"+this.renderId).wrap("<div class='"+this.cls+"'></div>");
	}
	else if(this.height){
		$("#"+this.renderId).wrap("<div style='height:"+this.height+"px;overflow:hidden;'></div>");
		return;
	}else{
		$("#"+this.renderId).wrap("<div></div>");
	}
	$("#"+this.renderId).css("overflow","auto");
};
// 开始滚动
Action.Scroll.prototype.start = function(){
	var THIS = this;
	if(THIS.timmer) {
		clearInterval(THIS.timmer);
		THIS.timmer = null;
	}
	var _oNeiDiv = $("#"+this.renderId);
	var _oWaiDiv = $("#"+this.renderId).parent();
	_oWaiDiv.unbind("mouseover");
	_oWaiDiv.unbind("mouseout");
	
	var _nDivHeight = _oNeiDiv.height();
	if(_nDivHeight <= _oWaiDiv.height()){
		return;
	}
	var _sHtml = _oNeiDiv.html();
	var _nSpeed=0;
	_oNeiDiv.append(_sHtml);
	var _fnTimmer = function(){
		_nSpeed=_nSpeed+1;
		 if(_nSpeed>=_nDivHeight){
			 _nSpeed = 0;
		 }
		 _oWaiDiv.scrollTop(_nSpeed); 
	};
	THIS.timmer = window.setInterval(_fnTimmer,THIS.speed);
	_oWaiDiv.mouseover(function(){
		clearInterval(THIS.timmer);
		THIS.timmer = null;
	});
	_oWaiDiv.mouseout(function(){
		if(THIS.timmer==null) {
			THIS.timmer=window.setInterval(_fnTimmer,THIS.speed);
		}
	});
};

// 上下滚动层特效实现
// 如果一个div太长，则可以实现让其上下自由滚动
Action.DownUp = function(p) {
	p = p || {};
	//这里继承无间隙滚动的dom，不继承原型方法，这和无间隙滚动的构造函数相同
	Action.Scroll.call(this, p);
};
// div下滚动
Action.DownUp.prototype.down = function() {
	var THIS = this;
	var _oNeiDiv = $("#"+this.renderId);
	var _oWaiDiv = $("#"+this.renderId).parent();
	var _nDivHeight = _oNeiDiv.height();
	var _nWaiHeight = _oWaiDiv.height();
	if(_nDivHeight<=_nWaiHeight || _oWaiDiv.scrollTop()<=0 ) {
		return;
	}
	var _fnTimmer = function(){
		if(_oWaiDiv.scrollTop()<=0){
			 THIS.stop();
			 return;
		 }
		 _oWaiDiv.scrollTop(_oWaiDiv.scrollTop()-1); 
	};
	THIS.timmer = window.setInterval(_fnTimmer,THIS.speed);
};
// div上滚动
Action.DownUp.prototype.up=function() {
	var THIS = this;
	var _oNeiDiv = $("#"+this.renderId);
	var _oWaiDiv = $("#"+this.renderId).parent();
	var _nDivHeight = _oNeiDiv.height();
	var _nWaiHeight = _oWaiDiv.height();
	if(_nDivHeight<=_nWaiHeight || (_oWaiDiv.scrollTop()+_nWaiHeight)>=_nDivHeight ) {
		return;
	}
	var _fnTimmer = function(){
		 if((_oWaiDiv.scrollTop()+_nWaiHeight)>=_nDivHeight){
			 THIS.stop();
			 return;
		 }
		 _oWaiDiv.scrollTop(_oWaiDiv.scrollTop()+1); 
	};
	THIS.timmer = window.setInterval(_fnTimmer,THIS.speed);
};
// div停止滚动
Action.DownUp.prototype.stop = function(){
	var THIS = this;
	if(THIS.timmer) {
		clearInterval(THIS.timmer);
		THIS.timmer = null;
	}
};